import fs from "fs";
// import { dirname } from "node:path"
// import { fileURLToPath } from "node:url"

// const filename_esm = fileURLToPath(import.meta.url);
// const dirname_esm = dirname(filename_esm);
import Koa from 'koa'

export default (app: Koa) => {
  fs.readdirSync(__dirname).forEach((file) => {
    // console.log(file.toString())
    if (file === "index.ts") return; // index.js文件不需要
    import(`./${file}`).then(module => {
      // console.debug("dirname_esm",router.default);
      const router = module.default;
      app.use(router.routes()).use(router.allowedMethods());
    });

  });
};

